#include "Goomba.h"

const std::map<std::string, Animation> Goomba::animations = Goomba::getAnimations();
const std::map<std::string, Animation> Goomba::getAnimations()
{
    std::map<std::string, Animation> anims;
    anims["walk"] = Animation("walk", ANIMATION_FLAG_NONE, 2, 0);
    anims["die"] = Animation("die", ANIMATION_FLAG_ONE_TIME, 3, 1);
    return anims;
}

Goomba::Goomba()
{
    animExecutor.SetAnimation(animations.at("walk"), ANIM_SLOW);
	SpeedX=-2;
	FacingRight=true;
}
 
bool Goomba::OnLoad()
{
    if (CEntity::OnLoad("./images/goomba.png", 16, 16) == false)
    {
        return false;
    }
    return true;
}
 
void Goomba::OnLoop()
{
    CEntity::OnLoop();
	if(SpeedX==0)
	{
		FacingRight=!FacingRight;
		SpeedX=FacingRight?2:-2;
	}


    if (Dying && !animExecutor.getIsAnimating())
    {
        die();
    }
}
 
void Goomba::OnRender(SDL_Surface* Surf_Display)
{
    CEntity::OnRender(Surf_Display);
}
 
void Goomba::OnCleanup()
{
    CEntity::OnCleanup();
}
 
void Goomba::OnAnimate()
{
    CEntity::OnAnimate();
}

void Goomba::OnCollision(CEntity* Entity)
{
    if(Entity->Type == ENTITY_TYPE_PLAYER)
    {
        if(((Entity->Y + Entity->Height) < (Y + Height/2)) && !Dying)
        {
            Dying = true;
            //.....\o/......^.... SHARK ATTACK
            animExecutor.SetAnimation(animations.at("die"), ANIM_SLOW);
        }
    }
}

void Goomba::die()
{
    Enemy::die();
}

Acceleration Goomba::UpdateAcceleration()
{
	Acceleration accel = Enemy::UpdateAcceleration();

	float xAccel = accel.getX();
	float yAccel = accel.getY();

	return Acceleration(xAccel, yAccel);
}